//
//  QpFootDetailsTableViewCell.m
//  Tour
//
//  Created by 才诗琦 on 16/3/11.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "QpFootDetailsTableViewCell.h"

@implementation QpFootDetailsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {

        //图片
        self.photo = [[UIImageView alloc] init];
        [self.contentView addSubview:_photo];
        
        
        self.desc = [[UILabel alloc] init];
        _desc.numberOfLines = 0;
        _desc.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_desc];
        
        self.firstname = [[UILabel alloc] init];
        _firstname.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_firstname];
        
    }
    return self;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
#warning 3. 计算高度后 这是label的高度
    // [self class] 表示当前类
    // layout 是cell显示前 最后一个方法 此时label上已经被赋值了文本
    CGFloat h = [[self class]heightWithText:_desc.text];
    _photo.frame = CGRectMake(15, 10, self.contentView.frame.size.width - 30, (self.contentView.frame.size.width - 30)*360 / 710);
    _firstname.frame = CGRectMake(20, (self.contentView.frame.size.width - 30)*360 / 710 - 40, self.contentView.frame.size.width - 30, 20);
    _desc.frame = CGRectMake(15, (self.contentView.frame.size.width - 30)*360 / 710 +10, self.contentView.frame.size.width - 30, h);
    
}
#warning 2. 计算文本高度
+ (CGFloat)heightWithText:(NSString *)text
{
    // 保存文本属性(大小)
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:17]};
    // 预设尺寸 文本最大不超过这个尺寸
    // 根据设置的宽度 计算高度(宽度和label保持一致)
    CGSize size = CGSizeMake(375 - 30, 1000);
    // 根据文本 计算出一个CGRect
    // 参数1: 尺寸范围
    // 参数2: 文本属性
    // 参数3: 按照什么方式获取rect
    // 参数4: nil
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    // 返回得到的高度
    return rect.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
